package com.zkk.web;

import com.zkk.pojo.User;
import com.zkk.service.UserService;
import com.zkk.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

import static java.lang.Integer.parseInt;

@WebServlet("/findById")
public class findById extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        UserService userService=new UserServiceImpl();
        User user = userService.findById(Integer.valueOf(id));//这样就查询单个了
        HttpSession session = req.getSession();
        session.setAttribute("result",user);//把结果给修改的Servlet方法modifyById
        session.setAttribute("number",id);//把id也进行设置键值对给其他servlet使用
        resp.sendRedirect("/modifyUser.html");


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
